package com.kzl.android.net.impl;

import android.content.Context;
import android.util.Log;
import com.caucho.hessian.client.HessianProxyFactory;
import com.kzl.android.dao.BaseAPI;
import com.kzl.android.entity.request.BaseRequest;
import com.kzl.android.entity.response.BaseResponse;
import com.kzl.android.net.HttpUtil;
import com.kzl.android.utils.GPUrls;

import java.net.MalformedURLException;

/**
 * Created with IntelliJ IDEA.
 * User: <a href="kezhenlu@qq.com">kezhenlu</a>
 * Date: 13-5-4
 * Time: 上午10:14
 * To change this template use File | Settings | File Templates.
 */
public class HessianHttpUtilImpl implements HttpUtil {
    private final String TAG = getClass().getName();

    @Override
    public BaseResponse connect(BaseRequest baseRequest, Context context) {
        HessianProxyFactory factory = new HessianProxyFactory();
        try {
            factory.setDebug(true);
            factory.setReadTimeout(5000);
            BaseAPI baseAPI = factory.create(BaseAPI.class, GPUrls.baseUrl, context.getClassLoader());
            return baseAPI.hello(baseRequest);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (Exception e) {
            Log.e(TAG, "exception,what's wrong");
            e.printStackTrace();
        }
        return null;
    }
}
